#include "stdafx.h"
#include "Flower.h"


CFlower::CFlower()
{
	m_pos.x = 600, m_pos.y = 480;
	m_isBloom = 0;
	m_preBloomTime = 0;
	SetImage();
}


CFlower::~CFlower()
{
}


void CFlower::DrawToBack(IplImage* Bg, int MapMoveDis)
{
	int keyb = 255, keyg = 255, keyr = 255;
	if(m_pos.x - MapMoveDis < Bg->width && m_pos.x - MapMoveDis >= -m_img[m_isBloom]->width + 1)	
		CTools::DrawToBackground(m_pos.x - MapMoveDis, m_pos.y, Bg, m_img[m_isBloom], keyb, keyg, keyr);
}


void CFlower::ChangeState(IplImage* Bg)
{
	if (clock() - m_preBloomTime > 1000) {
		m_preBloomTime = clock();
		if (m_isBloom == 1)	m_isBloom = 0;
		else m_isBloom = 1;
	}
}


void CFlower::SetImage()
{
	char filename[40];
	for (int i = 0; i < MAX_FLOWERIMAGE_COUNT; i++) {
		sprintf_s(filename,"./pic/flower/%d.jpg",i);
		m_img[i] = cvLoadImage(filename);
	}
}
